<!--
 * @Author: WangSir 3036970150@qq.com
 * @Date: 2022-11-25 18:28:44
 * @LastEditors: WangSir 3036970150@qq.com
 * @LastEditTime: 2022-11-28 11:38:51
 * @FilePath: \vue_express\src\pages\changePasswordPage\ChangePasswordPage.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div class='ChangePasswordPage'>
       <div class="box">
            <div class="lable">
               <el-input v-model="oldPassword" type="password" placeholder="请输入原密码"></el-input>
               <el-input v-model="newPassword" type="password" placeholder="请输入新密码"></el-input>
               <el-input v-model="rePassword" type="password" placeholder="再次输入密码"></el-input> 
            </div>
            <el-button type="primary" @click.native="updatePassword()" >确认修改
               </el-button>  
       </div>
    </div>
   </template>
   
   <script>
import { updateAdminPassword } from '@/utils/request'
   export default {
    name: 'ChangePasswordPage',
    data(){
    return {
      oldPassword:'',
      newPassword:'',
      rePassword:''
    }
    },
    computed:{},
    components: {},
    created(){},
    mounted(){},
    methods: {
      updatePassword(){
         if(this.newPassword==this.rePassword&&this.new!=''&&this.rePassword!=''){
            var user = JSON.parse(sessionStorage.getItem("user"))
            //原始密码一致
            if(user.password==this.oldPassword){
                  let admindata = {
                     uid:user.uid,
                     password:this.newPassword
                  }
                  updateAdminPassword(admindata).then((res)=>{
               if(res.status){
                  this.$message({
                   type: "success",
                   message: res.data.message+",请重新登录",
                 });
                 sessionStorage.removeItem("user")
                 this.$router.replace("/loginPage")
               }else{
                  this.$message({
                   type: "failer",
                   message: res.message,
                 });
               }
            })
         }}    
         
      }
    }
   }
   </script>
   <style scoped>
   .ChangePasswordPage{
      display: flex;
      justify-content: center;
      align-items: center;
   }
   .box{
      width: 300px;
      height: 350px;
      border: 1px solid rgb(231, 230, 230);
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      align-items: center;
      border-radius: 10px;
      box-shadow: 1px 3px 10px rgb(187, 185, 185);
   }
   .lable{
      width: 250px;
      height: 200px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      align-items: center;
   }
   
   </style>
   